//
//  OrderDetailTableViewCell.m
//  B2C
//
//  Created by 李小龙 on 2017/8/2.
//  Copyright © 2017年 lixiaolong. All rights reserved.
//

#import "OrderDetailTableViewCell.h"

#define OrderDetailButtonBaseTag 100000

@implementation OrderDetailTableViewCell
#pragma mark - 订单详情
+ (instancetype)orderDetailCellWith:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath count:(NSInteger)count type:(OrderType)type {
    NSString *identifier = @"";
    NSInteger index = 0;
    switch (indexPath.section) {
        case 0:
            switch (indexPath.row) {
                case 0:
                    identifier = @"cellEighth";
                    index = 7;
                    break;
                case 1:
                    identifier = @"cellSecond";
                    index = 1;
                    break;
                default:
                    break;
            }
            break;
        case 1:
        {
            if (type == OrderTypeFromMineStore) {
                if (indexPath.row == 0) {
                    identifier = @"cellNinth";
                    index = 8;
                } else if (indexPath.row == count+1) {
                    identifier = @"cellTenth";
                    index = 9;
                } else if (indexPath.row == count+2) {
                    identifier = @"cellFifth";
                    index = 4;
                } else {
                    identifier = @"cellThird";
                    index = 2;
                }
            } else {
                if (indexPath.row%2 == 0) {
                    identifier = @"cellThird";
                    index = 2;
                } else if (indexPath.row%2 == 1) {
                    identifier = @"cellFourth";
                    index = 3;
                }
            }
        } break;
        case 2:
            switch (indexPath.row) {
                case 0:
                    identifier = @"cellSixth";
                    index = 5;
                    break;
                case 1:
                    identifier = @"cellFifth";
                    index = 4;
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
    OrderDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"OrderDetailTableViewCell" owner:self options:nil] objectAtIndex:index];
        if (type == OrderTypeFromSelf && indexPath.section == 1 && indexPath.row%2 == 1 ) {
            [cell.fourthRefundButton setHalfCircleWithColor:[UIColor grayTextColor]];
            [cell.fourthReportButton setHalfCircleWithColor:[UIColor grayTextColor]];
        }
        if (type == OrderTypeFromMineStore && indexPath.section == 1 && indexPath.row > 0 && indexPath.row < count+1) {
            CGFloat buttonH = 26;
            CGFloat buttonW = 75;
            CGFloat kong = 5;
            CGFloat bottom = 9;
            cell.thirdOrderButton = [OrderHalfButton orderButtonWithType:-1 frame:CGRectMake(ScreenWidth-(kong+buttonW), 144-buttonH-bottom, buttonW, buttonH) buttonTitle:@"" color:[UIColor gray66Color] borderColor:[UIColor grayTextColor]];
            [cell.contentView addSubview:cell.thirdOrderButton];
        }
    }
    return cell;
}
- (void)updateCellWith:(OrderModel *)model indexPath:(NSIndexPath *)indexPath type:(OrderType)type {
    switch (indexPath.section) {
        case 0:
        {
            switch (indexPath.row) {
                case 0:
                {
                    if (model.isrefund) {
                        [self.eighthIconImageView setImage:[UIImage imageNamed:@"refundicon"]];
                        [self.eighthTitleLabel setText:@"退款申请"];
                    } else {
                        // 状态0已提交，1已付款，2已发货，3已签收，4已评价，5已取消，6已删除，7已退款，8退款申请
                        switch (model.omstatus.intValue) {
                            case 0:
                            {
                                [self.eighthIconImageView setImage:[UIImage imageNamed:@"consignment"]];
                                [self.eighthTitleLabel setText:@"等待付款"];
                                if (model.omtype.integerValue == 1) {
                                    [self.eightPriceLabel setText:[NSString stringWithFormat:@"需付积分：%ld",model.omprice.integerValue]];
                                } else {
                                    [self.eightPriceLabel setText:[NSString stringWithFormat:@"需付款：¥%@",model.omprice]];
                                }
                            } break;
                            case 1:
                            {
                                [self.eighthIconImageView setImage:[UIImage imageNamed:@"consignment"]];
                                [self.eighthTitleLabel setText:@"等待卖家发货"];
                                [self.eightPriceLabel setText:@""];
                            } break;
                            case 2:
                            {
                                [self.eighthIconImageView setImage:[UIImage imageNamed:@"consignment"]];
                                [self.eighthTitleLabel setText:@"等待买家收货"];
                                [self.eightPriceLabel setText:@""];
                            } break;
                            case 3:
                            {
                                [self.eighthIconImageView setImage:[UIImage imageNamed:@"evaluate_icon"]];
                                [self.eighthTitleLabel setText:@"订单已完成，给个好评吧!"];
                                [self.eightPriceLabel setText:@""];
                            } break;
                            case 4:
                            {
                                [self.eighthIconImageView setImage:[UIImage imageNamed:@"evaluate_icon"]];
                                [self.eighthTitleLabel setText:@"买家已评价"];
                                [self.eightPriceLabel setText:@""];
                            } break;
                            case 5:
                            {
                                [self.eighthIconImageView setImage:[UIImage imageNamed:@"refundicon"]];
                                [self.eighthTitleLabel setText:@"订单已取消"];
                                [self.eightPriceLabel setText:@""];
                            } break;
                            case 6:
                            {
                                [self.eighthIconImageView setImage:[UIImage imageNamed:@"refundicon"]];
                                [self.eighthTitleLabel setText:@"订单已删除"];
                                [self.eightPriceLabel setText:@""];
                            } break;
                            case 7:
                            {
                                [self.eighthIconImageView setImage:[UIImage imageNamed:@"refundicon"]];
                                [self.eighthTitleLabel setText:@"卖家已退款"];
                                [self.eightPriceLabel setText:@""];
                            } break;
                            case 8:
                            {
                                [self.eighthIconImageView setImage:[UIImage imageNamed:@"consignment"]];
                                [self.eighthTitleLabel setText:@"正在退款，请耐心等待..."];
                                [self.eightPriceLabel setText:@""];
                            } break;
                            default:
                                break;
                        }
                    }
                } break;
                case 1:
                {
                    [self.secondNameLabel setText:model.deliveryname];
                    [self.secondPhoneLabel setText:[LXLIsPhoneNumber phoneNumber:model.deliverytel]];
                    [self.secondAddressLabel setText:model.deliveryaddress];
                    
                } break;
                default:
                    break;
            }
        } break;
        case 1:
        {
            if (type == OrderTypeFromMineStore) {
                if (indexPath.row == 0) {
                    /*
                    [self.ninthTitleLabel setText:model.shop.sname];
                    if ([model.shop.sid isEqualToString:@"0"]) {
                        // 自营
                        [self.ninthIconImageView setImage:[UIImage imageNamed:@"logo_small"]];
                        [self.ninthTypeImageView setImage:[UIImage imageNamed:@"self_support"]];
                    } else {
                        [self.ninthIconImageView setImage:[UIImage imageNamed:@"shopicon"]];
                        if ([model.shop.stype isEqualToString:@"1"]) {
                            // 企业
                            [self.ninthTypeImageView setImage:[UIImage imageNamed:@"enterprise"]];
                        } else {
                            // 个人
                            [self.ninthTypeImageView setImage:[UIImage imageNamed:@"personal"]];
                        }
                    }
                     */
                } else if (indexPath.row == model.ordergoods.count+1) {
                    // 显示的按钮
                    [self createOrderType:model.isrefund type:model.omstatus.intValue indexPath:indexPath];
                    [self.tenthBackView setBackgroundColor:[UIColor grayfaColor]];
                    [self.tenthServiceButton setImage:[UIImage imageNamed:@"contact_666"] forState:UIControlStateNormal];
                    [self.tenthServiceButton setTitle:@"买家" forState:UIControlStateNormal];
                } else if (indexPath.row == model.ordergoods.count+2) {
                    //[self.fifthContentLabel setText:[NSString stringWithFormat:@"共计%@件商品，合计：",model.omnumber]];
                    if (model.omtype.integerValue == 1) {
                        [self.fifthContentLabel setText:@"实付积分："];
                        [self.fifthPriceLabel setText:[NSString stringWithFormat:@"%ld",model.omprice.integerValue]];
                    } else {
                        [self.fifthContentLabel setText:@"实付款："];
                        [self.fifthPriceLabel setText:[NSString stringWithFormat:@"¥%@",model.omprice]];
                    }
                } else {
                    OrdersonModel *goodModel = model.ordergoods[indexPath.row-1];
                    
                    [self.thirdImageView sd_setImageWithURL:GetUrl(goodModel.gimg) placeholderImage:PlaceholderImageSmall changeContentModel:UIViewContentModeScaleAspectFill];
                    [self.thirdNameLabel setText:goodModel.gname];
                    [self.thirdCountLabel setText:[NSString stringWithFormat:@"x%ld",(long)goodModel.ognumber.integerValue]];
                    if (goodModel.isigoods) {
                        [self.thirdPriceLabel setText:[NSString stringWithFormat:@"%ld积分",goodModel.gintegral.integerValue]];
                    } else {
                        [self.thirdPriceLabel setText:[NSString stringWithFormat:@"¥%@",goodModel.gprice]];
                    }
                    // 状态0已提交，1已付款，2已发货，3已签收，4已评价，5已取消，6已删除，7退款申请，8已退款
                    if (model.isrefund) {
                        [self.thirdOrderButton setHidden:YES];
                    } else {
                        switch (model.omstatus.intValue) {
                            case 0:
                            {
                                [self.thirdOrderButton setHidden:NO];
                                [self.thirdOrderButton setOrderButtonStyleWithType:OrderButtonTypeStoreChangePrice buttonTitle:@"修改价格" color:[UIColor gray66Color] borderColor:[UIColor grayTextColor]];
                                [self.thirdOrderButton addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                            } break;
                            case 4:
                            {
                                [self.thirdOrderButton setHidden:NO];
                                [self.thirdOrderButton setOrderButtonStyleWithType:OrderButtonTypeStoreCheckEvaluate buttonTitle:@"查看评价" color:[UIColor gray66Color] borderColor:[UIColor grayTextColor]];
                                [self.thirdOrderButton addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                            } break;
                            default:
                                [self.thirdOrderButton setHidden:YES];
                                break;
                        }
                    }
                    
                    if (indexPath.row == model.ordergoods.count) {
                        [self.thirdLineView setHidden:YES];
                    } else {
                        [self.thirdLineView setHidden:NO];
                    }
                }
            } else {
                if (indexPath.row%2 == 1) {
                    // 显示的按钮
                    // 退款按钮
                    [self.fourthRefundButton setTitle:@"退款" forState:UIControlStateNormal];
                    [self.fourthReportButton setTitle:@"举报" forState:UIControlStateNormal];
                    switch (model.omstatus.integerValue) {
                        case 1: case 2: case 3:
                        {
                            if (!model.isrefund) {
                                [self.fourthReportButton setHidden:NO];
                                if (indexPath.row == model.ordergoods.count*2) {
                                    [self.fourthLineView setHidden:YES];
                                } else {
                                    [self.fourthLineView setHidden:NO];
                                }
                                if (model.omtype.integerValue == 1) {
                                    [self.fourthRefundButton setHidden:YES];
                                    self.fourthRefundButtonRLayout.constant = 0;
                                    self.fourthRefundButtonWLayout.constant = 0;
                                } else {
                                    [self.fourthRefundButton setHidden:NO];
                                    self.fourthRefundButtonRLayout.constant = 5;
                                    self.fourthRefundButtonWLayout.constant = 75;
                                }
                            } else {
                                [self.fourthLineView setHidden:YES];
                                [self.fourthRefundButton setHidden:YES];
                                [self.fourthReportButton setHidden:YES];
                            }
                        } break;
                        default:
                        {
                            [self.fourthLineView setHidden:YES];
                            [self.fourthRefundButton setHidden:YES];
                            [self.fourthReportButton setHidden:YES];
                        } break;
                    }
                    
                } else if (indexPath.row%2 == 0) {
                    OrdersonModel *goodModel = model.ordergoods[indexPath.row/2];
                    
                    [self.thirdImageView sd_setImageWithURL:GetUrl(goodModel.gimg) placeholderImage:PlaceholderImageSmall changeContentModel:UIViewContentModeScaleAspectFill];
                    [self.thirdNameLabel setText:goodModel.gname];
                    [self.thirdCountLabel setText:[NSString stringWithFormat:@"x%ld",(long)goodModel.ognumber.integerValue]];
                    if (goodModel.isigoods) {
                        [self.thirdPriceLabel setText:[NSString stringWithFormat:@"%ld积分",goodModel.gintegral.integerValue]];
                    } else {
                        [self.thirdPriceLabel setText:[NSString stringWithFormat:@"¥%@",goodModel.gprice]];
                    }
                    // 属性
                    NSString *specs = @"";
                    for (NSInteger i = 0; i < goodModel.otop.count; i++) {
                        OtopsModel *otops = goodModel.otop[i];
                        if (i == 0) {
                            specs = otops.taname;
                        } else {
                            specs = [NSString stringWithFormat:@"%@;%@",specs,otops.taname];
                        }
                    }
                    [self.thirdSpecsLabel setText:specs];
                    
                    switch (model.omstatus.integerValue) {
                        case 1: case 2: case 3:
                        {
                            [self.thirdLineView setHidden:YES];
                        } break;
                        default:
                        {
                            if (indexPath.row+1 == model.ordergoods.count*2) {
                                [self.thirdLineView setHidden:YES];
                            } else {
                                [self.thirdLineView setHidden:NO];
                            }
                        } break;
                    }
                }
            }
        } break;
        case 2:
            if (indexPath.row == 0) {
                NSString *contentStr;
                if (TextIsNotNil(model.omid)) {
                    contentStr = [NSString stringWithFormat:@"订单编号：%@",model.omid];
                }
                if (TextIsNotNil(model.createtime)) {
                    contentStr = [NSString stringWithFormat:@"%@\n%@",contentStr,[NSString stringWithFormat:@"下单时间：%@",[DateSomeThing getDateStrWithTimestampstr:model.createtime formatStr:@"yyyy-MM-dd HH:mm"]]];
                }
                if (TextIsNotNil(model.paytime)) {
                    contentStr = [NSString stringWithFormat:@"%@\n%@",contentStr,[NSString stringWithFormat:@"付款时间：%@",[DateSomeThing getDateStrWithTimestampstr:model.paytime formatStr:@"yyyy-MM-dd HH:mm"]]];
                }
                if (TextIsNotNil(model.dealtime)) {
                    contentStr = [NSString stringWithFormat:@"%@\n%@",contentStr,[NSString stringWithFormat:@"成交时间：%@",[DateSomeThing getDateStrWithTimestampstr:model.dealtime formatStr:@"yyyy-MM-dd HH:mm"]]];
                }
                [self.sixthOrderNumberLabel setText:contentStr];
                
            } else if (indexPath.row == 1) {
                // 状态0已提交，1已付款，2已发货，3已签收，4已评价，5已取消，6已删除，7退款申请，8已退款
                if (model.omstatus.integerValue == 0) {
                    if (model.omtype.integerValue == 1) {
                        [self.fifthContentLabel setText:@"需付积分："];
                    } else {
                        [self.fifthContentLabel setText:@"需付款："];
                    }
                } else {
                    if (model.omtype.integerValue == 1) {
                        [self.fifthContentLabel setText:@"实付积分："];
                    } else {
                        [self.fifthContentLabel setText:@"实付款："];
                    }
                }
                if (model.omtype.integerValue == 1) {
                    [self.fifthPriceLabel setText:[NSString stringWithFormat:@"%ld积分",model.omprice.integerValue]];
                } else {
                    [self.fifthPriceLabel setText:[NSString stringWithFormat:@"¥%@",model.omprice]];
                }
            }
            break;
        default:
            break;
    }
}
#pragma mark - 退款订单详情
+ (instancetype)refundDetailCellWith:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath count:(NSInteger)count type:(OrderType)type{
    NSString *identifier = @"";
    NSInteger index = 0;
    switch (indexPath.section) {
        case 0:
        {
            switch (indexPath.row) {
                case 0:
                    identifier = @"cellEighth";
                    index = 7;
                    break;
                case 1:
                {
                    if (type == OrderTypeRefundDismiss || type == OrderTypeMineStoreRefundDismiss) {
                        identifier = @"cellEleventh";
                        index = 10;
                    } else {
                        identifier = @"cellFirst";
                        index = 0;
                    }
                } break;
                default:
                    break;
            }
        } break;
        case 1:
        {
            identifier = @"cellThird";
            index = 2;
        } break;
        case 2:
        {
            if (type == OrderTypeRefundDismiss || type == OrderTypeMineStoreRefundDismiss) {
                if (indexPath.row == 0) {
                    identifier = @"cellFirst";
                    index = 0;
                } else {
                    identifier = @"cellSeventh";
                    index = 6;
                }
            } else {
                identifier = @"cellSeventh";
                index = 6;
            }
        } break;
        default:
            break;
    }
    OrderDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"OrderDetailTableViewCell" owner:self options:nil] objectAtIndex:index];
//        if (indexPath.section == 1 && indexPath.row == count) {
//            [cell.fourthRefundButton setHalfCircleWithColor:[UIColor grayTextColor]];
//        }
        
    }
    return cell;
}
- (void)updateRefundDetailCellWith:(OrderModel *)model indexPath:(NSIndexPath *)indexPath count:(NSInteger)count type:(OrderType)type {
    // 0已提交，1已退款，2退款失败，3退款驳回
    switch (indexPath.section) {
        case 0:
        {
            switch (indexPath.row) {
                case 0:
                {
                    [self.eighthIconImageView setImage:[UIImage imageNamed:@"refundicon"]];
                    switch (type) {
                        case OrderTypeRefund:
                        {
                            [self.eighthTitleLabel setText:@"正在退款，请耐心等待..."];
                            [self.eightPriceLabel setText:@""];
                        } break;
                        case OrderTypeMineStoreRefund:
                        {
                            [self.eighthTitleLabel setText:@"请处理退款申请"];
                            [self.eightPriceLabel setText:@""];
                        } break;
                        case OrderTypeRefundSuccess: case OrderTypeMineStoreRefundSuccess:
                        {
                            [self.eighthTitleLabel setText:@"退款成功"];
                            [self.eightPriceLabel setText:@""];
                        } break;
                        case OrderTypeRefundFailure: case OrderTypeMineStoreRefundFailure:
                        {
                            [self.eighthTitleLabel setText:@"卖家同意退款"];
                            [self.eightPriceLabel setText:@""];
                        } break;
                        case OrderTypeRefundDismiss: case OrderTypeMineStoreRefundDismiss:
                        {
                            [self.eighthTitleLabel setText:@"卖家拒绝退款"];
                            [self.eightPriceLabel setText:@""];
                        } break;
                        default:
                            break;
                    }
                } break;
                case 1:
                {
                    if (type == OrderTypeRefundDismiss || type == OrderTypeMineStoreRefundDismiss) {
                        //卖家拒绝退款原因
                        [self.eleventhTitleLabel setText:@"卖家反馈"];
                        [self.eleventhContentLabel setText:model.refund.lastObject.feedback];
                    } else {
                        [self.firstLeftLabel setText:@"退款金额"];
                        [self.firstRightLabel setText:[NSString stringWithFormat:@"¥%@",model.refund.lastObject.rprice]];
                        [self.firstLineView setHidden:YES];
                    }
                } break;
                default:
                    break;
            }
        } break;
        case 1:
        {
            [self.thirdImageView sd_setImageWithURL:GetUrl(model.gimg) placeholderImage:PlaceholderImageSmall changeContentModel:UIViewContentModeScaleAspectFill];
            [self.thirdNameLabel setText:model.gname];
            [self.thirdCountLabel setText:[NSString stringWithFormat:@"x%ld",(long)model.ognumber.integerValue]];
            [self.thirdPriceLabel setText:[NSString stringWithFormat:@"¥%@",model.gprice]];
            // 属性
            OrdersonModel *goodModel = model.ordergoods[indexPath.row];
            NSString *specs = @"";
            for (NSInteger i = 0; i < goodModel.otop.count; i++) {
                OtopsModel *otops = goodModel.otop[i];
                if (i == 0) {
                    specs = otops.taname;
                } else {
                    specs = [NSString stringWithFormat:@"%@;%@",specs,otops.taname];
                }
            }
            [self.thirdSpecsLabel setText:specs];

        } break;
        case 2:
        {
            if (type == OrderTypeRefundDismiss || type == OrderTypeMineStoreRefundDismiss) {
                if (indexPath.row == 0) {
                    [self.firstLeftLabel setText:@"退款金额"];
                    [self.firstRightLabel setText:[NSString stringWithFormat:@"¥%@",model.refund.lastObject.rprice]];
                    [self.firstLineView setHidden:NO];
                } else {
                    [self.seventhReasonLabel setText:[NSString stringWithFormat:@"退款原因：%@",model.refund.lastObject.rcontent]];
                    [self.seventhPriceLabel setText:[NSString stringWithFormat:@"退款金额：¥%@",model.refund.lastObject.rprice]];
                    [self.seventhDateLabel setText:[NSString stringWithFormat:@"申请日期：%@",[DateSomeThing getDateStrWithTimestampstr:model.refund.lastObject.createtime formatStr:@"yyyy-MM-dd HH:mm"]]];
                }
            } else {
                [self.seventhReasonLabel setText:[NSString stringWithFormat:@"退款原因：%@",model.refund.lastObject.rcontent]];
                [self.seventhPriceLabel setText:[NSString stringWithFormat:@"退款金额：¥%@",model.refund.lastObject.rprice]];
                [self.seventhDateLabel setText:[NSString stringWithFormat:@"申请日期：%@",[DateSomeThing getDateStrWithTimestampstr:model.refund.lastObject.createtime formatStr:@"yyyy-MM-dd HH:mm"]]];
            }
        } break;
        default:
            break;
    }
    
    
//    switch (indexPath.section) {
//        case 0:
//        {
//            switch (indexPath.row) {
//                case 0:
//                {
//                    [self.firstLeftLabel setText:@"退款状态"];
//                    // 0已提交，1已退款，2退款失败，3退款驳回
//                    switch (model.refund.lastObject.rstatus.intValue) {
//                        case 0:
//                            [self.firstRightLabel setText:@"退款中"];
//                            break;
//                        case 1:
//                            [self.firstRightLabel setText:@"已退款"];
//                            break;
//                        case 2:
//                            [self.firstRightLabel setText:@"退款失败"];
//                            break;
//                        case 3:
//                            [self.firstRightLabel setText:@"退款驳回"];
//                            break;
//                        default:
//                            break;
//                    }
//                } break;
//                case 1:
//                {
//                    [self.firstLeftLabel setText:@"退款金额"];
//                    [self.firstRightLabel setText:[NSString stringWithFormat:@"¥%.2f",model.refund.lastObject.rprice.floatValue]];
//                } break;
//                default:
//                    break;
//            }
//            
//        } break;
//        case 1:
//        {
//            if (indexPath.row == count) {
//                // 取消退款
//                if ([model.refund.lastObject.rstatus isEqualToString:@"0"]) {
//                    [self.fourthRefundButton setTitle:@"取消退款" forState:UIControlStateNormal];
//                    [self.fourthRefundButton setEnabled:YES];
//                } else {
//                    [self.fourthRefundButton setTitle:@"已完成" forState:UIControlStateDisabled];
//                    [self.fourthRefundButton setEnabled:NO];
//                }
//            } else if (indexPath.row == count+1) {
//                [self.seventhReasonLabel setText:[NSString stringWithFormat:@"退款原因：%@",model.refund.lastObject.rcontent]];
//                [self.seventhPriceLabel setText:[NSString stringWithFormat:@"退款金额：¥%.2f",model.refund.lastObject.rprice.floatValue]];
//                [self.seventhDateLabel setText:[NSString stringWithFormat:@"申请日期：%@",[DateSomeThing getDateStrWithTimestampstr:model.refund.lastObject.createtime formatStr:@"yyyy-MM-dd HH:mm"]]];
//            } else {
//                OrdersonModel *goodModel = model.goods[indexPath.row];
//                
//                [self.thirdImageView sd_setImageWithURL:GetUrl(goodModel.gimg) placeholderImage:PlaceholderImagePictures];
//                [self.thirdNameLabel setText:goodModel.gname];
//                [self.thirdCountLabel setText:[NSString stringWithFormat:@"x%@",goodModel.osnumber]];
//                [self.thirdPriceLabel setText:[NSString stringWithFormat:@"¥%.2f",goodModel.osprice.floatValue]];
//                // 属性
//                NSString *specs = @"";
//                for (NSInteger i = 0; i < goodModel.otops.count; i++) {
//                    OtopsModel *otops = goodModel.otops[i];
//                    if (i == 0) {
//                        specs = otops.taname;
//                    } else {
//                        specs = [NSString stringWithFormat:@"%@;%@",specs,otops.taname];
//                    }
//                }
//                [self.thirdSpecsLabel setText:specs];
//            }
//        } break;
//        default:
//            break;
//    }
}

#pragma mark - 退款原因申请
+ (instancetype)refundCellWith:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath count:(NSInteger)count {
    NSString *identifier = @"";
    NSInteger index = 0;
    switch (indexPath.section) {
        case 0:
            identifier = @"cellThird";
            index = 2;
            break;
        case 1:
        {
            switch (indexPath.row) {
                case 0:
                    identifier = @"cellTwelfth";
                    index = 11;
                    break;
                case 1:
                    identifier = @"cellFirst";
                    index = 0;
                    break;
                default:
                    break;
            }
        } break;
        case 2:
            identifier = @"cellEleventh";
            index = 10;
            break;
        default:
            break;
    }
    OrderDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"OrderDetailTableViewCell" owner:self options:nil] objectAtIndex:index];
    }
    return cell;
}
- (void)updateRefundCellWith:(OrderModel *)model indexPath:(NSIndexPath *)indexPath count:(NSInteger)count {
    switch (indexPath.section) {
        case 0:
        {
            OrdersonModel *goodModel = model.ordergoods[indexPath.row];
            
            [self.thirdImageView sd_setImageWithURL:GetUrl(goodModel.gimg) placeholderImage:PlaceholderImageSmall changeContentModel:UIViewContentModeScaleAspectFill];
            [self.thirdNameLabel setText:goodModel.gname];
            [self.thirdCountLabel setText:[NSString stringWithFormat:@"x%ld",(long)goodModel.ognumber.integerValue]];
            [self.thirdPriceLabel setText:[NSString stringWithFormat:@"¥%@",goodModel.gprice]];
//            if ([goodModel.gpricetype isEqualToString:@"0"]) {
//                NSString *allPrice;
//                if (TextIsNotNil(goodModel.goldprice)) {
//                    allPrice = goodModel.goldprice;
//                } else {
//                    double priceValue = goodModel.gprice.doubleValue * goodModel.gshare.doubleValue * 100;
//                    allPrice = [NSString stringWithFormat:@"%.2f",round(priceValue)/100];
//                }
//                [self.thirdCountLabel setText:@"x1"];
//                [self.thirdPriceLabel setText:[NSString stringWithFormat:@"¥%@",allPrice]];
//            } else {
//                [self.thirdCountLabel setText:[NSString stringWithFormat:@"x%ld",(long)goodModel.gshare.integerValue]];
//                [self.thirdPriceLabel setText:[NSString stringWithFormat:@"¥%.2f",goodModel.gprice.doubleValue]];
//            }
            // 属性
            NSString *specs = @"";
            for (NSInteger i = 0; i < goodModel.otop.count; i++) {
                OtopsModel *otops = goodModel.otop[i];
                if (i == 0) {
                    specs = otops.taname;
                } else {
                    specs = [NSString stringWithFormat:@"%@;%@",specs,otops.taname];
                }
            }
            [self.thirdSpecsLabel setText:specs];

            
            [self setBackgroundColor:[UIColor whiteColor]];
            if (indexPath.row < count-1) {
                [self.thirdLineView setHidden:NO];
            } else {
                [self.thirdLineView setHidden:YES];
            }
        } break;
        case 1:
        {
            switch (indexPath.row) {
                case 0:
                {
                    
                } break;
                case 1:
                {
                    [self.firstLeftLabel setText:@"退款金额"];
                    NSString *price;
                    if (model.ordergoods) {
                        price = [[NSString stringWithFormat:@"%.2f",model.ordergoods.firstObject.gprice.doubleValue*model.ordergoods.firstObject.ognumber.integerValue] replacePriceSuffix];
                    } else {
                        price = model.refund.lastObject.rprice;
                    }
                    [self.firstRightLabel setText:[NSString stringWithFormat:@"¥%@",price]];
                    [self.firstLineView setHidden:YES];
                } break;
                default:
                    break;
            }
        } break;
        case 2:
        {
            [self.eleventhTitleLabel setText:@"退款须知"];
            //MARK:测试
            [self.eleventhContentLabel setText:@"1. 买家支付后，3天内可无理由退货，买家需自己承担退货邮费。\n2. 买家支付后3-99天，如需退货，平台将收取10%的折旧费。"];
        } break;
        default:
            break;
    }
}
#pragma mark - 举报商品
+ (instancetype)reportCellWith:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath count:(NSInteger)count {
    NSString *identifier = @"";
    NSInteger index = 0;
    switch (indexPath.section) {
        case 0:
            identifier = @"cellThird";
            index = 2;
            break;
        case 1:
        {
            identifier = @"cellTwelfth";
            index = 11;
        } break;
        default:
            break;
    }
    OrderDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"OrderDetailTableViewCell" owner:self options:nil] objectAtIndex:index];
    }
    return cell;
}
- (void)updateReportCellWith:(OrderModel *)model indexPath:(NSIndexPath *)indexPath count:(NSInteger)count {
    switch (indexPath.section) {
        case 0:
        {
            OrdersonModel *goodModel = model.ordergoods[indexPath.row];
            
            [self.thirdImageView sd_setImageWithURL:GetUrl(goodModel.gimg) placeholderImage:PlaceholderImageSmall changeContentModel:UIViewContentModeScaleAspectFill];
            [self.thirdNameLabel setText:goodModel.gname];
            [self.thirdCountLabel setText:[NSString stringWithFormat:@"x%ld",(long)goodModel.ognumber.integerValue]];
            if (goodModel.isigoods) {
                [self.thirdPriceLabel setText:[NSString stringWithFormat:@"%ld积分",goodModel.gintegral.integerValue]];
            } else {
                [self.thirdPriceLabel setText:[NSString stringWithFormat:@"¥%@",goodModel.gprice]];
            }
            // 属性
            NSString *specs = @"";
            for (NSInteger i = 0; i < goodModel.otop.count; i++) {
                OtopsModel *otops = goodModel.otop[i];
                if (i == 0) {
                    specs = otops.taname;
                } else {
                    specs = [NSString stringWithFormat:@"%@;%@",specs,otops.taname];
                }
            }
            [self.thirdSpecsLabel setText:specs];
            
            [self setBackgroundColor:[UIColor whiteColor]];
            if (indexPath.row < count-1) {
                [self.thirdLineView setHidden:NO];
            } else {
                [self.thirdLineView setHidden:YES];
            }
        } break;
        case 1:
        {
            [self.twelfthContentTextView setPlaceholder:@"请填写举报原因"];
            [self.twelfthLineView setHidden:YES];
        } break;
        default:
            break;
    }
}
#pragma mark - Action
- (void)removeFourthBackViewSubView {
    for (UIView *view in self.tenthBackView.subviews) {
        if (view.tag != 10000) {
            [view removeFromSuperview];
        } else {
            NSLog(@"%@",view);
        }
    }
}

- (void)createOrderType:(BOOL)isRefund type:(NSInteger)type indexPath:(NSIndexPath *)indexPath {
    // 状态0已提交，1已付款，2已发货，3已签收，4已评价，5已取消，6已删除，7退款申请，8已退款
    CGFloat buttonY = 9;
    CGFloat buttonW = 75;
    CGFloat kong = 5;
    [self removeFourthBackViewSubView];
    switch (type) {
        case 0:
        {
            OrderHalfButton *button = [OrderHalfButton orderButtonWithType:OrderButtonTypeStoreClose frame:CGRectMake(ScreenWidth-(kong+buttonW), buttonY, buttonW, self.tenthBackView.height-buttonY*2) buttonTitle:@"关闭订单" color:[UIColor gray66Color] borderColor:[UIColor grayTextColor]];
            [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            [button setTag:indexPath.section+OrderDetailButtonBaseTag];
            [self.tenthBackView addSubview:button];
//            for (NSInteger i = 1; i <= 2; i++) {
//                CGRect frame = CGRectMake(ScreenWidth-(kong+buttonW)*i, buttonY, buttonW, self.tenthBackView.height-buttonY*2);
//
//                OrderButtonType type;
//                NSString *buttonTitle;
//                UIColor *color = [UIColor gray66Color], *borderColor = [UIColor grayTextColor];
//                if (i == 1) {
//                    type = OrderButtonTypeStoreClose;
//                    buttonTitle = @"关闭订单";
//                } else {
//                    type = OrderButtonTypeStoreChangePrice;
//                    buttonTitle = @"修改价格";
//                }
//
//                OrderHalfButton *button = [OrderHalfButton orderButtonWithType:type frame:frame buttonTitle:buttonTitle color:color borderColor:borderColor];
//                [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//                [button setTag:indexPath.section+OrderDetailButtonBaseTag];
//                [self.tenthBackView addSubview:button];
//            }
        } break;
        case 1:
        {
            if (isRefund) {
                for (NSInteger i = 1; i <= 3; i++) {
                    CGRect frame = CGRectMake(ScreenWidth-(kong+buttonW)*i, buttonY, buttonW, self.tenthBackView.height-buttonY*2);
                    
                    OrderButtonType type;
                    NSString *buttonTitle;
                    UIColor *color = [UIColor gray66Color], *borderColor = [UIColor grayTextColor];
                    if (i == 1) {
                        type = OrderButtonTypeStoreRefund;
                        buttonTitle = @"退货申请";
                    } else if (i == 2) {
                        type = OrderButtonTypeStoreClose;
                        buttonTitle = @"关闭订单";
                    } else {
                        type = OrderButtonTypeStoreSendOut;
                        buttonTitle = @"去发货";
                    }
                    
                    OrderHalfButton *button = [OrderHalfButton orderButtonWithType:type frame:frame buttonTitle:buttonTitle color:color borderColor:borderColor];
                    [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                    [button setTag:indexPath.section+OrderDetailButtonBaseTag];
                    [self.tenthBackView addSubview:button];
                }
                
            } else {
                for (NSInteger i = 1; i <= 2; i++) {
                    CGRect frame = CGRectMake(ScreenWidth-(kong+buttonW)*i, buttonY, buttonW, self.tenthBackView.height-buttonY*2);
                    
                    OrderButtonType type;
                    NSString *buttonTitle;
                    UIColor *color = [UIColor gray66Color], *borderColor = [UIColor grayTextColor];
                    if (i == 1) {
                        type = OrderButtonTypeStoreClose;
                        buttonTitle = @"关闭订单";
                    } else {
                        type = OrderButtonTypeStoreSendOut;
                        buttonTitle = @"去发货";
                    }
                    
                    OrderHalfButton *button = [OrderHalfButton orderButtonWithType:type frame:frame buttonTitle:buttonTitle color:color borderColor:borderColor];
                    [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                    [button setTag:indexPath.section+OrderDetailButtonBaseTag];
                    [self.tenthBackView addSubview:button];
                }
            }
        } break;
        case 2:
        {
            if (isRefund) {
                for (NSInteger i = 1; i <= 2; i++) {
                    CGRect frame = CGRectMake(ScreenWidth-(kong+buttonW)*i, buttonY, buttonW, self.tenthBackView.height-buttonY*2);
                    
                    OrderButtonType type;
                    NSString *buttonTitle;
                    UIColor *color = [UIColor gray66Color], *borderColor = [UIColor grayTextColor];
                    if (i == 1) {
                        type = OrderButtonTypeStoreRefund;
                        buttonTitle = @"退货申请";
                    } else {
                        type = OrderButtonTypeStoreCheck;
                        buttonTitle = @"查看物流";
                    }
                    
                    OrderHalfButton *button = [OrderHalfButton orderButtonWithType:type frame:frame buttonTitle:buttonTitle color:color borderColor:borderColor];
                    [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                    [button setTag:indexPath.section+OrderDetailButtonBaseTag];
                    [self.tenthBackView addSubview:button];
                }
                
            } else {
                OrderHalfButton *button = [OrderHalfButton orderButtonWithType:OrderButtonTypeStoreCheck
                                                                         frame:CGRectMake(ScreenWidth-(kong+buttonW), buttonY, buttonW, self.tenthBackView.height-buttonY*2)
                                                                   buttonTitle:@"查看物流"
                                                                         color:[UIColor gray66Color]
                                                                   borderColor:[UIColor grayTextColor]];
                [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                [button setTag:indexPath.section+OrderDetailButtonBaseTag];
                [self.tenthBackView addSubview:button];
            }
        } break;
        case 3:
        {
            if (isRefund) {
                for (NSInteger i = 1; i <= 2; i++) {
                    CGRect frame = CGRectMake(ScreenWidth-(kong+buttonW)*i, buttonY, buttonW, self.tenthBackView.height-buttonY*2);
                    
                    OrderButtonType type;
                    NSString *buttonTitle;
                    UIColor *color = [UIColor gray66Color], *borderColor = [UIColor grayTextColor];
                    if (i == 1) {
                        type = OrderButtonTypeStoreRefund;
                        buttonTitle = @"退货申请";
                    } else {
                        type = OrderButtonTypeStoreCheck;
                        buttonTitle = @"查看物流";
                    }
                    
                    OrderHalfButton *button = [OrderHalfButton orderButtonWithType:type frame:frame buttonTitle:buttonTitle color:color borderColor:borderColor];
                    [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                    [button setTag:indexPath.section+OrderDetailButtonBaseTag];
                    [self.tenthBackView addSubview:button];
                }
                
            } else {
                OrderHalfButton *button = [OrderHalfButton orderButtonWithType:OrderButtonTypeStoreCheck
                                                                         frame:CGRectMake(ScreenWidth-(kong+buttonW), buttonY, buttonW, self.tenthBackView.height-buttonY*2)
                                                                   buttonTitle:@"查看物流"
                                                                         color:[UIColor gray66Color]
                                                                   borderColor:[UIColor grayTextColor]];
                [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                [button setTag:indexPath.section+OrderDetailButtonBaseTag];
                [self.tenthBackView addSubview:button];
            }
        } break;
        case 4:
        {
//            OrderHalfButton *button = [OrderHalfButton orderButtonWithType:OrderButtonTypeStoreCheckEvaluate
//                                                                     frame:CGRectMake(ScreenWidth-(kong+buttonW), buttonY, buttonW, self.tenthBackView.height-buttonY*2)
//                                                               buttonTitle:@"查看评价"
//                                                                     color:[UIColor gray66Color]
//                                                               borderColor:[UIColor grayTextColor]];
//            [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//            [button setTag:indexPath.section+OrderDetailButtonBaseTag];
//            [self.tenthBackView addSubview:button];
        } break;
        case 5:
        {
            OrderHalfButton *button = [OrderHalfButton orderButtonWithType:OrderButtonTypeStoreDelete frame:CGRectMake(ScreenWidth-(kong+buttonW), buttonY, buttonW, self.tenthBackView.height-buttonY*2) buttonTitle:@"删除订单" color:[UIColor orangePriceColor] borderColor:[UIColor orangePriceColor]];
            [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            [button setTag:indexPath.section+OrderDetailButtonBaseTag];
            [self.tenthBackView addSubview:button];
        } break;
        case 6:
        {
            
        } break;
        case 7:
        {
            OrderHalfButton *button = [OrderHalfButton orderButtonWithType:OrderButtonTypeStoreDelete frame:CGRectMake(ScreenWidth-(kong+buttonW), buttonY, buttonW, self.tenthBackView.height-buttonY*2) buttonTitle:@"删除订单" color:[UIColor orangePriceColor] borderColor:[UIColor orangePriceColor]];
            [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            [button setTag:indexPath.section+OrderDetailButtonBaseTag];
            [self.tenthBackView addSubview:button];
        } break;
        case 8:
        {
            OrderHalfButton *button = [OrderHalfButton orderButtonWithType:OrderButtonTypeStoreRefund
                                                                     frame:CGRectMake(ScreenWidth-(kong+buttonW), buttonY, buttonW, self.tenthBackView.height-buttonY*2)
                                                               buttonTitle:@"退货申请"
                                                                     color:[UIColor gray66Color]
                                                               borderColor:[UIColor grayTextColor]];
            [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            [button setTag:indexPath.section+OrderDetailButtonBaseTag];
            [self.tenthBackView addSubview:button];
        } break;
        default:
            break;
    }
    
}

- (void)createMineStoreOne:(OrderButtonType)buttonType buttonStr:(NSString *)buttonStr buttonColor:(UIColor *)buttonColor buttonBorderColor:(UIColor *)buttonBorderColor indexPath:(NSIndexPath *)indexPath {
    [self removeFourthBackViewSubView];
    CGFloat buttonY = 9;
    CGFloat buttonW = 75;
    CGFloat kong = 5;
    OrderHalfButton *button = [OrderHalfButton orderButtonWithType:buttonType
                                                             frame:CGRectMake(ScreenWidth-(kong+buttonW), buttonY, buttonW, self.tenthBackView.height-buttonY*2)
                                                       buttonTitle:buttonStr
                                                             color:buttonColor
                                                       borderColor:buttonBorderColor];
    [button addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [button setTag:indexPath.section+OrderDetailButtonBaseTag];
    [self.tenthBackView addSubview:button];
}

- (void)orderButtonAction:(OrderHalfButton *)button {
    DetailCellClickType detailType = DetailCellClickTypeNone;
    switch (button.type) {
        case OrderButtonTypeRefundCancel:
            // 取消退款
            detailType = DetailCellClickTypeRefundCancel;
            break;
        case OrderButtonTypeRefundAgain:
            // 重新申请
            detailType = DetailCellClickTypeRefundAgain;
            break;
        case OrderButtonTypeRefundDone:
            // 申请通过
            detailType = DetailCellClickTypeRefundDone;
            break;
        case OrderButtonTypeStoreRefundReject:
            // 拒绝退款
            detailType = DetailCellClickTypeStoreRefundReject;
            break;
        case OrderButtonTypeStoreRefundAgree:
            // 同意申请
            detailType = DetailCellClickTypeStoreRefundAgree;
            break;
        case OrderButtonTypeStoreChangePrice:
            // 我的店铺->修改价格
            detailType = DetailCellClickTypeStoreChangePrice;
            break;
        case OrderButtonTypeStoreCheckEvaluate:
            // 我的店铺->查看评价
            detailType = DetailCellClickTypeStoreCheckEvaluate;
            break;
        case OrderButtonTypeStoreClose:
            // 我的店铺->关闭订单
            detailType = DetailCellClickTypeStoreClose;
            break;
        case OrderButtonTypeStoreSendOut:
            // 我的店铺->去发货
            detailType = DetailCellClickTypeStoreSendOut;
            break;
        case OrderButtonTypeStoreCheck:
            // 我的店铺->查看物流
            detailType = DetailCellClickTypeStoreCheck;
            break;
        case OrderButtonTypeStoreDelete:
            // 我的店铺->删除订单
            detailType = DetailCellClickTypeStoreDelete;
            break;
        default:
            break;
    }
    if (self.detailBlock) {
        self.detailBlock(detailType);
    }
}
#pragma mark - IBAction
- (IBAction)refundButtonAction:(id)sender {
    if (self.detailBlock) {
        self.detailBlock(DetailCellClickTypeRefund);
    }
}
- (IBAction)reportButtonAction:(id)sender {
    if (self.detailBlock) {
        self.detailBlock(DetailCellClickTypeReport);
    }
}

- (IBAction)copyButtonAction:(id)sender {
    if (self.detailBlock) {
        self.detailBlock(DetailCellClickTypeCopy);
    }
}
- (IBAction)serviceButtonAction:(id)sender {
    if (self.detailBlock) {
        self.detailBlock(DetailCellClickTypeService);
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
